package com.huyong.android.weatherforecast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

//http://api.map.baidu.com/telematics/v3/weather?location=%E5%8C%97%E4%BA%AC&output=json&ak=FkPhtMBK0HTIQNh7gG4cNUttSTyr0nzo
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    ImageView addCityIv,moreIv;
    LinearLayout pointLayout;
    ViewPager mainVp;

    List<Fragment> fragmentList;
    //需要显示的城市的集合
    List<String>cityList;
    //表示ViewPager的页数指数起显示集合
    List<ImageView>imgList;
    private CityFragmentPageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addCityIv = findViewById(R.id.hy_main_add);
        moreIv=findViewById(R.id.hy_main_more);
        pointLayout=findViewById(R.id.hy_main_point);
        mainVp=findViewById(R.id.hy_main_vp);

        //添加点击事件
        addCityIv.setOnClickListener(this);
        moreIv.setOnClickListener(this);

        fragmentList=new ArrayList<>();
        cityList=new ArrayList<>();
        imgList=new ArrayList<>();

        if (cityList.size()==0) {
            cityList.add("武汉");
        }
        initPager();
        adapter = new CityFragmentPageAdapter(getSupportFragmentManager(), fragmentList);
        mainVp.setAdapter(adapter);

        //创建小圆点指示器
//        initPoint();

    }

    private void initPoint() {

    }

    private void initPager() {
        //创建Fragment对象,添加到ViewPager数据源当中
        for(int i=0;i<cityList.size();i++){
            CityWeatherFragment cityWeatherFragment = new CityWeatherFragment();
            Bundle bundle = new Bundle();
            bundle.putString("city",cityList.get(i));
            cityWeatherFragment.setArguments(bundle);
            fragmentList.add(cityWeatherFragment);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.hy_main_add:
                break;
            case R.id.hy_main_more:
                break;
        }
    }
}